<template>
  <div class="form-item-el">
    <div v-if="mode === 'DESIGN'">
      <el-input disabled :placeholder="placeholder" />
    </div>
    <div v-else>
      <el-input v-if="!$attrs.disabled" clearable v-model="_value" :placeholder="placeholder"></el-input>
      <a v-else :href="_value">{{ _value }}</a>
    </div>
  </div>
</template>

<script setup>
import { computed, getCurrentInstance } from "vue";
import { isEmpty } from "lodash";

const { proxy } = getCurrentInstance();
const props = defineProps({
  mode: {
    type: String,
    default: "DESIGN"
  },
  required: {
    type: Boolean,
    default: false
  },
  readonly: {
    type: Boolean,
    default: false
  },
  modelValue: {
    type: String,
    default: ""
  },
  placeholder: {
    type: String,
    default: "请输入内容"
  }
});
const emit = defineEmits(["update:modelValue"]);

const _value = computed({
  get() {
    return props.modelValue;
  },
  set(val) {
    emit("update:modelValue", val);
  }
});

if (isEmpty(_value.value) && !proxy.$attrs.disabled) {
  _value.value = proxy.$attrs.defaultValue;
}
</script>

<style lang="scss" scoped>
.text-input {
  width: 100%;
}
a {
  font-size: 14px;
  color: #007dff;
  line-height: 24px;
  text-decoration: underline;
  cursor: pointer;
}
</style>
